package com.suxin.web;

import com.suxin.domain.Good;
import com.suxin.domain.UserInfo;
import com.suxin.enums.GoodType;
import com.suxin.service.GoodsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author Tang
 * @classname GoodController
 * @description [  ]
 * @date 2021/6/25 14:47
 */
@RestController
@RequestMapping("/good")
public class GoodController {

    @Resource
    GoodsService goodsService;

    private final AtomicInteger atomicInteger = new AtomicInteger();

    @GetMapping("/insert")
    public Map<String, Object> insert() {
        Map<String, Object> map = new HashMap<>(8);
        goodsService.insert(new Good() {{
            setGoodsId(1);
            setGoodsName("STUDENT");
            setGoodsType(GoodType.STUDENT);
            setUserInfo(new UserInfo(){{
                setAge(18);
                setName("tang");
            }});
        }});
        map.put("msg", "success!");
        return map;
    }

    @GetMapping("/insertList")
    public Map<String, Object> insertList() {
        Map<String, Object> map = new HashMap<>(8);
        goodsService.insertList();
        map.put("msg", "success!");
        return map;
    }

    @GetMapping("/insert0")
    public Map<String, Object> insert0(int id) {
        Map<String, Object> map = new HashMap<>(8);
        goodsService.insert0(new Good() {{
            setGoodsId(id);
            setGoodsName("STUDENT");
            setGoodsType(GoodType.STUDENT);
        }});
        map.put("msg", "success!");
        return map;
    }

    @GetMapping("/insert1")
    public Map<String, Object> insert1(int id) {
        Map<String, Object> map = new HashMap<>(8);
        goodsService.insert1(new Good() {{
            setGoodsId(id);
            setGoodsName("STUDENT");
            setGoodsType(GoodType.STUDENT);
        }});
        map.put("msg", "success!");
        return map;
    }

    @GetMapping("/thread/insert")
    public Map<String, Object> threadInsert() {
        Map<String, Object> map = new HashMap<>(8);
        goodsService.threadInsert();
        map.put("msg", "success!");
        return map;
    }

    @GetMapping("/selectOne")
    public Good selectOne(Good good) {
        return goodsService.selectOne(good);
    }

}